home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr44 / frasrc19.zip / FRACSUBA.ASM < prev    next >
Assembly Source File  |  1995-02-15  |  24KB  |  1,038 lines

  1. ;    FRACASM.ASM - Assembler subroutines for fractals.c
  2.  
  3. ;             required for compatibility if Turbo ASM
  4. IFDEF ??version
  5. MASM51
  6. QUIRKS
  7. ENDIF
  8.  
  9. .MODEL    medium,c
  10.  
  11. .8086
  12.  
  13.     ; these must NOT be in any segment!!
  14.     ; this get's rid of TURBO-C fixup errors
  15.     extrn    multiply:far        ; this routine is in 'general.asm'
  16.  
  17.     extrn    floatbailout:word        ; this routine is in 'fractals.c'
  18.  
  19. .data
  20.  
  21.     extrn    lold:qword, lnew:qword    ; each defined as LCMPLX in fractals.c
  22.     extrn    ltempsqrx:dword     ; for fractals.c
  23.     extrn    ltempsqry:dword     ; for fractals.c
  24.     extrn    lmagnitud:dword     ; for fractals.c
  25.     extrn    llimit:dword        ; from calcfrac.c
  26.     extrn    llimit2:dword        ; from calcfrac.c
  27.     extrn    bitshift:word        ; fudgefactor for integer math
  28.     extrn    overflow:word        ; error from integer math
  29.  
  30. .code FRACTALS_TEXT
  31.  
  32. ;; Note: the check for overflow is now in StandardFractal(), JCO 2/12/95
  33.  
  34. asmlMODbailout    proc near
  35. ;
  36. ; equivalent to the C code:
  37. ;  ltempsqrx = lsqr(lnew.x); ltempsqry = lsqr(lnew.y);
  38. ;  lmagnitud = ltempsqrx + ltempsqry;
  39. ;  if (lmagnitud >= llimit || lmagnitud < 0 || labs(lnew.x) > llimit2
  40. ;     || labs(lnew.y) > llimit2 || overflow)
  41. ;           { overflow=0; return(1); }
  42. ;  lold = lnew;
  43. ;  return(0);
  44. ;
  45. ;  ltempsqrx = lsqr(lnew.x);
  46.     push    bitshift
  47.     push    WORD PTR lnew+2
  48.     push    WORD PTR lnew
  49.     push    WORD PTR lnew+2
  50.     push    WORD PTR lnew
  51.     call    FAR PTR multiply
  52.     mov    WORD PTR ltempsqrx,ax
  53.     mov    WORD PTR ltempsqrx+2,dx
  54. ;  ltempsqry = lsqr(lnew.y);
  55.     push    bitshift
  56.     push    WORD PTR lnew+6
  57.     push    WORD PTR lnew+4
  58.     push    WORD PTR lnew+6
  59.     push    WORD PTR lnew+4
  60.     call    FAR PTR multiply
  61.     add    sp,20
  62.     mov    WORD PTR ltempsqry,ax
  63.     mov    WORD PTR ltempsqry+2,dx
  64. ;  lmagnitud = ltempsqrx + ltempsqry;
  65.     add    ax,WORD PTR ltempsqrx
  66.     adc    dx,WORD PTR ltempsqrx+2
  67.     mov    WORD PTR lmagnitud,ax
  68.     mov    WORD PTR lmagnitud+2,dx
  69. ;  if (lmagnitud >= llimit
  70.     cmp    dx,WORD PTR llimit+2
  71.     jl    chkvs0
  72.     jg    bailout
  73.     cmp    ax,WORD PTR llimit
  74.     jae    bailout
  75. ;   || lmagnitud < 0
  76. chkvs0: or    dx,dx
  77.     js    bailout
  78. ;   || labs(lnew.x) > llimit2        ; This test and next one are extraneous:
  79. ;    mov    ax,WORD PTR lnew        ; take    x > llimit2  and sqr both sides
  80. ;    mov    dx,WORD PTR lnew+2    ;       x^2 > llimit
  81. ;    or    dx,dx                ; if    x^2 > llimit then surely
  82. ;    jge    lnewx                ; x^2 + y^2 > llimit
  83. ;    neg    ax                ; which was just checked!
  84. ;    adc    dx,0
  85. ;    neg    dx
  86. ;lnewx:    cmp    dx,WORD PTR llimit2+2
  87. ;    jl    chklnewy
  88. ;    jg    bailout
  89. ;    cmp    ax,WORD PTR llimit2
  90. ;    ja    bailout
  91. ;   || labs(lnew.y) > llimit2
  92. ;chklnewy:
  93. ;    mov    ax,WORD PTR lnew+4
  94. ;    mov    dx,WORD PTR lnew+6
  95. ;    or    dx,dx
  96. ;    jge    lnewy
  97. ;    neg    ax
  98. ;    adc    dx,0
  99. ;    neg    dx
  100. ;lnewy:    cmp    dx,WORD PTR llimit2+2
  101. ;    jl    chkoflow
  102. ;    jg    bailout
  103. ;    cmp    ax,WORD PTR llimit2
  104. ;    ja    bailout
  105. ;   || overflow)
  106. chkoflow:
  107. ;    cmp    overflow,0
  108. ;    jne    bailout
  109. ;  else {
  110. ;  lold = lnew;
  111.     mov    ax,WORD PTR lnew
  112.     mov    dx,WORD PTR lnew+2
  113.     mov    WORD PTR lold,ax
  114.     mov    WORD PTR lold+2,dx
  115.     mov    ax,WORD PTR lnew+4
  116.     mov    dx,WORD PTR lnew+6
  117.     mov    WORD PTR lold+4,ax
  118.     mov    WORD PTR lold+6,dx
  119. ;  return(0); }
  120.     sub    ax,ax
  121.     ret
  122. bailout:
  123. ;  { overflow=0; return(1); }
  124. ;    mov    overflow,0
  125.     mov    ax,1
  126.     ret
  127. asmlMODbailout    endp
  128.  
  129. asmlREALbailout    proc near
  130. ;
  131. ; equivalent to the C code:
  132. ;  ltempsqrx = lsqr(lnew.x); ltempsqry = lsqr(lnew.y);
  133. ;  if (ltempsqrx >= llimit || overflow)
  134. ;           { overflow=0; return(1); }
  135. ;  lold = lnew;
  136. ;  return(0);
  137. ;
  138. ;  ltempsqry = lsqr(lnew.y);
  139.     push    bitshift
  140.     push    WORD PTR lnew+6
  141.     push    WORD PTR lnew+4
  142.     push    WORD PTR lnew+6
  143.     push    WORD PTR lnew+4
  144.     call    FAR PTR multiply
  145.     mov    WORD PTR ltempsqry,ax
  146.     mov    WORD PTR ltempsqry+2,dx
  147. ;  ltempsqrx = lsqr(lnew.x);
  148.     push    bitshift
  149.     push    WORD PTR lnew+2
  150.     push    WORD PTR lnew
  151.     push    WORD PTR lnew+2
  152.     push    WORD PTR lnew
  153.     call    FAR PTR multiply
  154.     add    sp,20
  155.     mov    WORD PTR ltempsqrx,ax
  156.     mov    WORD PTR ltempsqrx+2,dx
  157. ;  lmagnitud = ltempsqrx + ltempsqry;
  158.     add    ax,WORD PTR ltempsqry
  159.     adc    dx,WORD PTR ltempsqry+2
  160.     mov    WORD PTR lmagnitud,ax
  161.     mov    WORD PTR lmagnitud+2,dx
  162.     mov    ax,WORD PTR ltempsqrx    ; restore ltempsqrx to ax & dx
  163.     mov    dx,WORD PTR ltempsqrx+2
  164. ;  if (ltempsqrx >= llimit
  165.     cmp    dx,WORD PTR llimit+2
  166.     jl    chkoflow
  167.     jg    bailout
  168.     cmp    ax,WORD PTR llimit
  169.     jae    bailout
  170. ;   || overflow)
  171. chkoflow:
  172. ;    cmp    overflow,0
  173. ;    jne    bailout
  174. ;  else {
  175. ;  lold = lnew;
  176.     mov    ax,WORD PTR lnew
  177.     mov    dx,WORD PTR lnew+2
  178.     mov    WORD PTR lold,ax
  179.     mov    WORD PTR lold+2,dx
  180.     mov    ax,WORD PTR lnew+4
  181.     mov    dx,WORD PTR lnew+6
  182.     mov    WORD PTR lold+4,ax
  183.     mov    WORD PTR lold+6,dx
  184. ;  return(0); }
  185.     sub    ax,ax
  186.     ret
  187. bailout:
  188. ;  { overflow=0; return(1); }
  189. ;    mov    overflow,0
  190.     mov    ax,1
  191.     ret
  192. asmlREALbailout    endp
  193.  
  194. asmlIMAGbailout    proc near
  195. ;
  196. ; equivalent to the C code:
  197. ;  ltempsqrx = lsqr(lnew.x); ltempsqry = lsqr(lnew.y);
  198. ;  if (ltempsqry >= llimit || overflow)
  199. ;           { overflow=0; return(1); }
  200. ;  lold = lnew;
  201. ;  return(0);
  202. ;
  203. ;  ltempsqrx = lsqr(lnew.x);
  204.     push    bitshift
  205.     push    WORD PTR lnew+2
  206.     push    WORD PTR lnew
  207.     push    WORD PTR lnew+2
  208.     push    WORD PTR lnew
  209.     call    FAR PTR multiply
  210.     mov    WORD PTR ltempsqrx,ax
  211.     mov    WORD PTR ltempsqrx+2,dx
  212. ;  ltempsqry = lsqr(lnew.y);
  213.     push    bitshift
  214.     push    WORD PTR lnew+6
  215.     push    WORD PTR lnew+4
  216.     push    WORD PTR lnew+6
  217.     push    WORD PTR lnew+4
  218.     call    FAR PTR multiply
  219.     add    sp,20
  220.     mov    WORD PTR ltempsqry,ax
  221.     mov    WORD PTR ltempsqry+2,dx
  222. ;  lmagnitud = ltempsqrx + ltempsqry;
  223.     add    ax,WORD PTR ltempsqrx
  224.     adc    dx,WORD PTR ltempsqrx+2
  225.     mov    WORD PTR lmagnitud,ax
  226.     mov    WORD PTR lmagnitud+2,dx
  227.     mov    ax,WORD PTR ltempsqry    ; restore ltempsqry to ax & dx
  228.     mov    dx,WORD PTR ltempsqry+2
  229. ;  if (ltempsqry >= llimit
  230.     cmp    dx,WORD PTR llimit+2
  231.     jl    chkoflow
  232.     jg    bailout
  233.     cmp    ax,WORD PTR llimit
  234.     jae    bailout
  235. ;   || overflow)
  236. chkoflow:
  237. ;    cmp    overflow,0
  238. ;    jne    bailout
  239. ;  else {
  240. ;  lold = lnew;
  241.     mov    ax,WORD PTR lnew
  242.     mov    dx,WORD PTR lnew+2
  243.     mov    WORD PTR lold,ax
  244.     mov    WORD PTR lold+2,dx
  245.     mov    ax,WORD PTR lnew+4
  246.     mov    dx,WORD PTR lnew+6
  247.     mov    WORD PTR lold+4,ax
  248.     mov    WORD PTR lold+6,dx
  249. ;  return(0); }
  250.     sub    ax,ax
  251.     ret
  252. bailout:
  253. ;  { overflow=0; return(1); }
  254. ;    mov    overflow,0
  255.     mov    ax,1
  256.     ret
  257. asmlIMAGbailout    endp
  258.  
  259. asmlORbailout    proc near
  260. ;
  261. ; equivalent to the C code:
  262. ;  ltempsqrx = lsqr(lnew.x); ltempsqry = lsqr(lnew.y);
  263. ;  if (ltempsqrx >= llimit || ltempsqry >= llimit || overflow)
  264. ;           { overflow=0; return(1); }
  265. ;  lold = lnew;
  266. ;  return(0);
  267. ;
  268. ;  ltempsqrx = lsqr(lnew.x);
  269.     push    bitshift
  270.     push    WORD PTR lnew+2
  271.     push    WORD PTR lnew
  272.     push    WORD PTR lnew+2
  273.     push    WORD PTR lnew
  274.     call    FAR PTR multiply
  275.     mov    WORD PTR ltempsqrx,ax
  276.     mov    WORD PTR ltempsqrx+2,dx
  277. ;  ltempsqry = lsqr(lnew.y);
  278.     push    bitshift
  279.     push    WORD PTR lnew+6
  280.     push    WORD PTR lnew+4
  281.     push    WORD PTR lnew+6
  282.     push    WORD PTR lnew+4
  283.     call    FAR PTR multiply
  284.     add    sp,20
  285.     mov    WORD PTR ltempsqry,ax
  286.     mov    WORD PTR ltempsqry+2,dx
  287. ;  lmagnitud = ltempsqrx + ltempsqry;
  288.     add    ax,WORD PTR ltempsqrx
  289.     adc    dx,WORD PTR ltempsqrx+2
  290.     mov    WORD PTR lmagnitud,ax
  291.     mov    WORD PTR lmagnitud+2,dx
  292.     mov    ax,WORD PTR ltempsqry    ; restore ltempsqry to ax & dx
  293.     mov    dx,WORD PTR ltempsqry+2
  294. ;  if (ltempsqry >= llimit
  295.     cmp    dx,WORD PTR llimit+2
  296.     jl    chkxnxt
  297.     jg    bailout
  298.     cmp    ax,WORD PTR llimit
  299.     jae    bailout
  300. ;   || ltempsqrx >= llimit
  301. chkxnxt:
  302.     mov    ax,WORD PTR ltempsqrx
  303.     mov    dx,WORD PTR ltempsqrx+2
  304.     cmp    dx,WORD PTR llimit+2
  305.     jl    chkoflow
  306.     jg    bailout
  307.     cmp    ax,WORD PTR llimit
  308.     jae    bailout
  309. ;   || overflow)
  310. chkoflow:
  311. ;    cmp    overflow,0
  312. ;    jne    bailout
  313. ;  else {
  314. ;  lold = lnew;
  315.     mov    ax,WORD PTR lnew
  316.     mov    dx,WORD PTR lnew+2
  317.     mov    WORD PTR lold,ax
  318.     mov    WORD PTR lold+2,dx
  319.     mov    ax,WORD PTR lnew+4
  320.     mov    dx,WORD PTR lnew+6
  321.     mov    WORD PTR lold+4,ax
  322.     mov    WORD PTR lold+6,dx
  323. ;  return(0); }
  324.     sub    ax,ax
  325.     ret
  326. bailout:
  327. ;  { overflow=0; return(1); }
  328. ;    mov    overflow,0
  329.     mov    ax,1
  330.     ret
  331. asmlORbailout    endp
  332.  
  333. asmlANDbailout    proc near
  334. ;
  335. ; equivalent to the C code:
  336. ;  ltempsqrx = lsqr(lnew.x); ltempsqry = lsqr(lnew.y);
  337. ;  if ((ltempsqrx >= llimit && ltempsqry >= llimit) || overflow)
  338. ;           { overflow=0; return(1); }
  339. ;  lold = lnew;
  340. ;  return(0);
  341. ;
  342. ;  ltempsqrx = lsqr(lnew.x);
  343.     push    bitshift
  344.     push    WORD PTR lnew+2
  345.     push    WORD PTR lnew
  346.     push    WORD PTR lnew+2
  347.     push    WORD PTR lnew
  348.     call    FAR PTR multiply
  349.     mov    WORD PTR ltempsqrx,ax
  350.     mov    WORD PTR ltempsqrx+2,dx
  351. ;  ltempsqry = lsqr(lnew.y);
  352.     push    bitshift
  353.     push    WORD PTR lnew+6
  354.     push    WORD PTR lnew+4
  355.     push    WORD PTR lnew+6
  356.     push    WORD PTR lnew+4
  357.     call    FAR PTR multiply
  358.     add    sp,20
  359.     mov    WORD PTR ltempsqry,ax
  360.     mov    WORD PTR ltempsqry+2,dx
  361. ;  lmagnitud = ltempsqrx + ltempsqry;
  362.     add    ax,WORD PTR ltempsqrx
  363.     adc    dx,WORD PTR ltempsqrx+2
  364.     mov    WORD PTR lmagnitud,ax
  365.     mov    WORD PTR lmagnitud+2,dx
  366.     mov    ax,WORD PTR ltempsqry    ; restore ltempsqry to ax & dx
  367.     mov    dx,WORD PTR ltempsqry+2
  368. ;  if ((ltempsqry >= llimit
  369.     cmp    dx,WORD PTR llimit+2
  370.     jl    chkoflow
  371.     jg    chkx
  372.     cmp    ax,WORD PTR llimit
  373.     jae    chkx
  374.     jmp    short chkoflow
  375. ;  && ltempsqrx >= llimit)
  376. chkx:    mov    ax,WORD PTR ltempsqrx
  377.     mov    dx,WORD PTR ltempsqrx+2
  378.     cmp    dx,WORD PTR llimit+2
  379.     jl    chkoflow
  380.     jg    bailout
  381.     cmp    ax,WORD PTR llimit
  382.     jae    bailout
  383. ;   || overflow)
  384. chkoflow:
  385. ;    cmp    overflow,0
  386. ;    jne    bailout
  387. ;  else {
  388. ;  lold = lnew;
  389.     mov    ax,WORD PTR lnew
  390.     mov    dx,WORD PTR lnew+2
  391.     mov    WORD PTR lold,ax
  392.     mov    WORD PTR lold+2,dx
  393.     mov    ax,WORD PTR lnew+4
  394.     mov    dx,WORD PTR lnew+6
  395.     mov    WORD PTR lold+4,ax
  396.     mov    WORD PTR lold+6,dx
  397. ;  return(0); }
  398.     sub    ax,ax
  399.     ret
  400. bailout:
  401. ;  { overflow=0; return(1); }
  402. ;    mov    overflow,0
  403.     mov    ax,1
  404.     ret
  405. asmlANDbailout    endp
  406.  
  407.  
  408. .386
  409.  
  410. asm386lMODbailout    proc near
  411. ;
  412. ; equivalent to the C code:
  413. ;  ltempsqrx = lsqr(lnew.x); ltempsqry = lsqr(lnew.y);
  414. ;  lmagnitud = ltempsqrx + ltempsqry;
  415. ;  if (lmagnitud >= llimit || lmagnitud < 0 || labs(lnew.x) > llimit2
  416. ;     || labs(lnew.y) > llimit2 || overflow)
  417. ;           { overflow=0; return(1); }
  418. ;  lold = lnew;
  419. ;  return(0);
  420. ;
  421. ;  ltempsqrx = lsqr(lnew.x);
  422.     push    bitshift
  423.     push    DWORD PTR lnew
  424.     push    DWORD PTR lnew
  425.     call    FAR PTR multiply
  426.     mov    WORD PTR ltempsqrx,ax
  427.     mov    WORD PTR ltempsqrx+2,dx
  428. ;  ltempsqry = lsqr(lnew.y);
  429.     push    bitshift
  430.     push    DWORD PTR lnew+4
  431.     push    DWORD PTR lnew+4
  432.     call    FAR PTR multiply
  433.     add    sp,20
  434.     mov    WORD PTR ltempsqry,ax
  435.     mov    WORD PTR ltempsqry+2,dx
  436. ;  lmagnitud = ltempsqrx + ltempsqry;
  437.     mov    eax,DWORD PTR ltempsqry
  438.     add    eax,DWORD PTR ltempsqrx
  439.     mov    DWORD PTR lmagnitud,eax
  440. ;  if (lmagnitud >= llimit
  441.     cmp    eax,DWORD PTR llimit
  442.     jae    bailout
  443. ;   || overflow)
  444. chkoflow:
  445. ;    cmp    overflow,0
  446. ;    jne    bailout
  447. ;  else {
  448. ;  lold = lnew;
  449.     mov    eax,DWORD PTR lnew
  450.     mov    DWORD PTR lold,eax
  451.     mov    eax,DWORD PTR lnew+4
  452.     mov    DWORD PTR lold+4,eax
  453. ;  return(0); }
  454.     sub    ax,ax
  455.     ret
  456. bailout:
  457. ;  { overflow=0; return(1); }
  458. ;    mov    overflow,0
  459.     mov    ax,1
  460.     ret
  461. asm386lMODbailout    endp
  462.  
  463. asm386lREALbailout    proc near
  464. ;
  465. ; equivalent to the C code:
  466. ;  ltempsqrx = lsqr(lnew.x); ltempsqry = lsqr(lnew.y);
  467. ;  if (ltempsqrx >= llimit || overflow)
  468. ;           { overflow=0; return(1); }
  469. ;  lold = lnew;
  470. ;  return(0);
  471. ;
  472. ;  ltempsqry = lsqr(lnew.y);
  473.     push    bitshift
  474.     push    DWORD PTR lnew+4
  475.     push    DWORD PTR lnew+4
  476.     call    FAR PTR multiply
  477.     mov    WORD PTR ltempsqry,ax
  478.     mov    WORD PTR ltempsqry+2,dx
  479. ;  ltempsqrx = lsqr(lnew.x);
  480.     push    bitshift
  481.     push    DWORD PTR lnew
  482.     push    DWORD PTR lnew
  483.     call    FAR PTR multiply
  484.     add    sp,20
  485.     mov    WORD PTR ltempsqrx,ax
  486.     mov    WORD PTR ltempsqrx+2,dx
  487. ;  lmagnitud = ltempsqrx + ltempsqry;
  488.     mov    eax,DWORD PTR ltempsqry
  489.     add    eax,DWORD PTR ltempsqrx
  490.     mov    DWORD PTR lmagnitud,eax
  491. ;  if (ltempsqrx >= llimit
  492.     mov    eax,DWORD PTR ltempsqrx
  493.     cmp    eax,DWORD PTR llimit
  494.     jae    bailout
  495. ;   || overflow)
  496. chkoflow:
  497. ;    cmp    overflow,0
  498. ;    jne    bailout
  499. ;  else {
  500. ;  lold = lnew;
  501.     mov    eax,DWORD PTR lnew
  502.     mov    DWORD PTR lold,eax
  503.     mov    eax,DWORD PTR lnew+4
  504.     mov    DWORD PTR lold+4,eax
  505. ;  return(0); }
  506.     sub    ax,ax
  507.     ret
  508. bailout:
  509. ;  { overflow=0; return(1); }
  510. ;    mov    overflow,0
  511.     mov    ax,1
  512.     ret
  513. asm386lREALbailout    endp
  514.  
  515. asm386lIMAGbailout    proc near
  516. ;
  517. ; equivalent to the C code:
  518. ;  ltempsqrx = lsqr(lnew.x); ltempsqry = lsqr(lnew.y);
  519. ;  if (ltempsqry >= llimit || overflow)
  520. ;           { overflow=0; return(1); }
  521. ;  lold = lnew;
  522. ;  return(0);
  523. ;
  524. ;  ltempsqrx = lsqr(lnew.x);
  525.     push    bitshift
  526.     push    DWORD PTR lnew
  527.     push    DWORD PTR lnew
  528.     call    FAR PTR multiply
  529.     mov    WORD PTR ltempsqrx,ax
  530.     mov    WORD PTR ltempsqrx+2,dx
  531. ;  ltempsqry = lsqr(lnew.y);
  532.     push    bitshift
  533.     push    DWORD PTR lnew+4
  534.     push    DWORD PTR lnew+4
  535.     call    FAR PTR multiply
  536.     add    sp,20
  537.     mov    WORD PTR ltempsqry,ax
  538.     mov    WORD PTR ltempsqry+2,dx
  539. ;  lmagnitud = ltempsqrx + ltempsqry;
  540.     mov    eax,DWORD PTR ltempsqry
  541.     add    eax,DWORD PTR ltempsqrx
  542.     mov    DWORD PTR lmagnitud,eax
  543. ;  if (ltempsqry >= llimit
  544.     mov    eax,DWORD PTR ltempsqry
  545.     cmp    eax,DWORD PTR llimit
  546.     jae    bailout
  547. ;   || overflow)
  548. chkoflow:
  549. ;    cmp    overflow,0
  550. ;    jne    bailout
  551. ;  else {
  552. ;  lold = lnew;
  553.     mov    eax,DWORD PTR lnew
  554.     mov    DWORD PTR lold,eax
  555.     mov    eax,DWORD PTR lnew+4
  556.     mov    DWORD PTR lold+4,eax
  557. ;  return(0); }
  558.     sub    ax,ax
  559.     ret
  560. bailout:
  561. ;  { overflow=0; return(1); }
  562. ;    mov    overflow,0
  563.     mov    ax,1
  564.     ret
  565. asm386lIMAGbailout    endp
  566.  
  567. asm386lORbailout    proc near
  568. ;
  569. ; equivalent to the C code:
  570. ;  ltempsqrx = lsqr(lnew.x); ltempsqry = lsqr(lnew.y);
  571. ;  if (ltempsqrx >= llimit || ltempsqry >= llimit || overflow)
  572. ;           { overflow=0; return(1); }
  573. ;  lold = lnew;
  574. ;  return(0);
  575. ;
  576. ;  ltempsqrx = lsqr(lnew.x);
  577.     push    bitshift
  578.     push    DWORD PTR lnew
  579.     push    DWORD PTR lnew
  580.     call    FAR PTR multiply
  581.     mov    WORD PTR ltempsqrx,ax
  582.     mov    WORD PTR ltempsqrx+2,dx
  583. ;  ltempsqry = lsqr(lnew.y);
  584.     push    bitshift
  585.     push    DWORD PTR lnew+4
  586.     push    DWORD PTR lnew+4
  587.     call    FAR PTR multiply
  588.     add    sp,20
  589.     mov    WORD PTR ltempsqry,ax
  590.     mov    WORD PTR ltempsqry+2,dx
  591. ;  lmagnitud = ltempsqrx + ltempsqry;
  592.     mov    eax,DWORD PTR ltempsqry
  593.     add    eax,DWORD PTR ltempsqrx
  594.     mov    DWORD PTR lmagnitud,eax
  595. ;  if (ltempsqry >= llimit
  596.     mov    eax,DWORD PTR ltempsqry
  597.     cmp    eax,DWORD PTR llimit
  598.     jae    bailout
  599. ;   || ltempsqrx >= llimit
  600. chkxnxt:
  601.     mov    eax,DWORD PTR ltempsqrx
  602.     cmp    eax,DWORD PTR llimit
  603.     jae    bailout
  604. ;   || overflow)
  605. chkoflow:
  606. ;    cmp    overflow,0
  607. ;    jne    bailout
  608. ;  else {
  609. ;  lold = lnew;
  610.     mov    eax,DWORD PTR lnew
  611.     mov    DWORD PTR lold,eax
  612.     mov    eax,DWORD PTR lnew+4
  613.     mov    DWORD PTR lold+4,eax
  614. ;  return(0); }
  615.     sub    ax,ax
  616.     ret
  617. bailout:
  618. ;  { overflow=0; return(1); }
  619. ;    mov    overflow,0
  620.     mov    ax,1
  621.     ret
  622. asm386lORbailout    endp
  623.  
  624. asm386lANDbailout    proc near
  625. ;
  626. ; equivalent to the C code:
  627. ;  ltempsqrx = lsqr(lnew.x); ltempsqry = lsqr(lnew.y);
  628. ;  if ((ltempsqrx >= llimit && ltempsqry >= llimit) || overflow)
  629. ;           { overflow=0; return(1); }
  630. ;  lold = lnew;
  631. ;  return(0);
  632. ;
  633. ;  ltempsqrx = lsqr(lnew.x);
  634.     push    bitshift
  635.     push    DWORD PTR lnew
  636.     push    DWORD PTR lnew
  637.     call    FAR PTR multiply
  638.     mov    WORD PTR ltempsqrx,ax
  639.     mov    WORD PTR ltempsqrx+2,dx
  640. ;  ltempsqry = lsqr(lnew.y);
  641.     push    bitshift
  642.     push    DWORD PTR lnew+4
  643.     push    DWORD PTR lnew+4
  644.     call    FAR PTR multiply
  645.     add    sp,20
  646.     mov    WORD PTR ltempsqry,ax
  647.     mov    WORD PTR ltempsqry+2,dx
  648. ;  lmagnitud = ltempsqrx + ltempsqry;
  649.     mov    eax,DWORD PTR ltempsqry
  650.     add    eax,DWORD PTR ltempsqrx
  651.     mov    DWORD PTR lmagnitud,eax
  652. ;  if ((ltempsqry >= llimit
  653.     mov    eax,DWORD PTR ltempsqry
  654.     cmp    eax,DWORD PTR llimit
  655.     jl    chkoflow
  656. ;  && ltempsqrx >= llimit)
  657. chkx:    mov    eax,DWORD PTR ltempsqrx
  658.     cmp    eax,DWORD PTR llimit
  659.     jae    bailout
  660. ;   || overflow)
  661. chkoflow:
  662. ;    cmp    overflow,0
  663. ;    jne    bailout
  664. ;  else {
  665. ;  lold = lnew;
  666.     mov    eax,DWORD PTR lnew
  667.     mov    DWORD PTR lold,eax
  668.     mov    eax,DWORD PTR lnew+4
  669.     mov    DWORD PTR lold+4,eax
  670. ;  return(0); }
  671.     sub    ax,ax
  672.     ret
  673. bailout:
  674. ;  { overflow=0; return(1); }
  675. ;    mov    overflow,0
  676.     mov    ax,1
  677.     ret
  678. asm386lANDbailout    endp
  679.  
  680.  
  681. ;  Fast fractal orbit calculation procs for Fractint.
  682. ;  By Chuck Ebbert   CIS: (76306,1226)
  683. ;
  684. ;    FManOWarfpFractal()
  685. ;    FJuliafpFractal()
  686. ;    FBarnsley1FPFractal()
  687. ;    FBarnsley2FPFractal()
  688. ;    FLambdaFPFractal()
  689. ;
  690. ;    asmfloatbailout()     -- bailout proc (NEAR proc used by above)
  691. ;        NOTE: asmfloatbailout() modifies SI and DI.
  692. ;
  693. ;  These will only run on machines with a 287 or a 387 (and a 486 of course.)
  694. ;
  695. ;  Some of the speed gains from this code are due to the storing of the NPU
  696. ;    status word directly to the AX register.  FRACTINT will use these
  697. ;     routines only when it finds a 287 or better coprocessor installed.
  698.  
  699. .286
  700. .287
  701.  
  702. .data
  703.  
  704.     extrn new:qword, old:qword, tmp:qword
  705.     extrn rqlim:qword, magnitude:qword, tempsqrx:qword, tempsqry:qword
  706.     extrn cpu:word, fpu:word, floatparm:word
  707.  
  708. .code FRACTALS_TEXT
  709.  
  710.     ; px,py = floatparm->x,y
  711.     ; ox,oy = oldx,oldy
  712.     ; nx,ny = newx,newy
  713.     ; nx2,ny2 = newxsquared,newysquared
  714.     ; tx,ty = tempx, tempy (used in lambda)
  715.  
  716. FManOWarfpFractal    proc uses si di
  717.                ; From Art Matrix via Lee Skinner
  718.     fld    tempsqrx        ; ox2
  719.     fsub    tempsqry        ; ox2-oy2
  720.     mov    bx,floatparm
  721.     fadd    tmp            ; ox2-oy2+tx
  722.     fadd    qword ptr [bx]        ; newx
  723.     fld    old            ; oldx newx
  724.     fmul    old+8            ; oldx*oldy newx
  725.     fadd    st,st            ; oldx*oldy*2 newx
  726.     fadd    tmp+8            ; oldx*oldy*2+tmp.y newx
  727.     fadd    qword ptr [bx+8]    ; newy newx
  728.     fstp    qword ptr new+8    ; newx
  729.     fstp    qword ptr new    ; stack is empty
  730.     mov    si,offset old        ; tmp=old
  731.     mov    di,offset tmp
  732.     mov    ax,ds
  733.     mov    es,ax
  734.     mov    cx,8
  735.     rep    movsw
  736. ;    call    near ptr asmfloatbailout
  737.     call    word ptr [floatbailout]
  738.     ret
  739. FManOWarfpFractal    endp
  740.  
  741. FJuliafpFractal proc uses si di
  742.     ; Julia/Mandelbrot floating-point orbit function.
  743.     fld    tempsqrx
  744.     fsub    tempsqry
  745.     mov    bx,floatparm
  746.     fadd    qword ptr [bx]        ;/* add floatparm->x */
  747.     fld    qword ptr old        ;/* now get 2*x*y+floatparm->y */
  748.     fmul    qword ptr old+8
  749.     fadd    st,st
  750.     fadd    qword ptr [bx+8]    ; add floatparm->y
  751.     fstp    qword ptr new+8    ; newx
  752.     fstp    qword ptr new    ; stack is empty
  753. ;    call    near ptr asmfloatbailout
  754.     call    word ptr [floatbailout]
  755.     ret
  756. FJuliafpFractal         endp
  757.  
  758. FBarnsley1FPFractal    proc uses si di
  759.     ; From Fractals Everywhere by Michael Barnsley
  760.     mov    bx,floatparm
  761.     fld    qword ptr [bx]        ;/* STACK: px */
  762.     fld    qword ptr [bx+8]    ;/* py px */
  763.     fld    qword ptr old        ;/* ox py px */
  764.     ftst                ;/*** we will want this later */
  765.     fstsw    ax            ;/*** 287 or better only */
  766.     fld    old+8            ;/* oy ox py px */
  767.     fld    st(1)            ;/* ox oy ox py px */
  768.     fmul    st,st(4)        ;/* ox*px oy ox py px */
  769.     fld    st(1)            ;/* oy ox*px oy ox py px */
  770.     fmul    st,st(4)        ;/* oy*py ox*px oy ox py px */
  771.     fsub                ;/* (ox*px-oy*py) oy ox py px */
  772.     fxch                ;/* oy (oxpx-oypy) ox py px */
  773.     fmul    st,st(4)        ;/* oy*px (oxpx-oypy) ox py px */
  774.     fxch    st(2)            ;/* ox (oxpx-oypy) oy*px py px */
  775.     fmul    st,st(3)        ;/* ox*py (oxpx-oypy) oy*px py px */
  776.     faddp    st(2),st        ;/* oxpx-oypy oypx+oxpy py px */
  777.     sahf                ;/*** use the saved status (finally) */
  778.     jb    BFPM1add
  779.     fsubrp    st(3),st        ;/* oypx+oxpy py nx */
  780.     fsubr                ;/* ny nx */
  781.     jmp    short BFPM1cont
  782. BFPM1add:
  783.     faddp    st(3),st        ;/* oypx+oxpy py nx */
  784.     fadd                ;/* ny nx */
  785. BFPM1cont:
  786.     fstp    qword ptr new+8    ; newx
  787.     fstp    qword ptr new    ; stack is empty
  788. ;    call    near ptr asmfloatbailout
  789.     call    word ptr [floatbailout]
  790.     ret
  791. FBarnsley1FPFractal endp
  792.  
  793. FBarnsley2FPFractal proc uses si di
  794.     ; Also from Fractals Everywhere
  795.     mov    bx,floatparm
  796.     fld    qword ptr [bx]        ;/* STACK: px */
  797.     fld    qword ptr [bx+8]    ;/* py px */
  798.     fld    qword ptr old        ;/* ox py px */
  799.     fld    qword ptr old+8     ;/* oy ox py px */
  800.     fld    st(1)            ;/* ox oy ox py px */
  801.     fmul    st,st(4)        ;/* ox*px oy ox py px */
  802.     fld    st(1)            ;/* oy ox*px oy ox py px */
  803.     fmul    st,st(4)        ;/* oy*py ox*px oy ox py px */
  804.     fsub                ;/* (ox*px-oy*py) oy ox py px */
  805.     fxch    st(2)            ;/* ox oy (oxpx-oypy) py px */
  806.     fmul    st,st(3)        ;/* ox*py oy (oxpx-oypy) py px */
  807.     fxch                ;/* oy ox*py (oxpx-oypy) py px */
  808.     fmul    st,st(4)        ;/* oy*px ox*py (oxpx-oypy) py px */
  809.     fadd                ;/* oypx+oxpy oxpx-oypy py px */
  810.     ftst
  811.     fstsw    ax            ;/* 287 or better only */
  812.     sahf
  813.     jb    BFPM2add
  814.     fsubrp    st(2),st        ;/* oxpx-oypy ny px */
  815.     fsubrp    st(2),st        ;/* ny nx */
  816.     jmp    short BFPM2cont
  817. BFPM2add:
  818.     faddp    st(2),st        ;/* oxpx-oypy ny px */
  819.     faddp    st(2),st        ;/* ny nx */
  820. BFPM2cont:
  821.     fstp    qword ptr new+8    ; newx
  822.     fstp    qword ptr new    ; stack is empty
  823. ;    call    near ptr asmfloatbailout
  824.     call    word ptr [floatbailout]
  825.     ret
  826. FBarnsley2FPFractal endp
  827.  
  828. FLambdaFPFractal proc uses si di
  829.     ; tempsqrx and tempsqry can be used -- the C code doesn't use them!
  830.     fld    tempsqry        ;oy2
  831.     fsub    tempsqrx        ;oy2-ox2
  832.     fld    old            ;ox oy2-ox2
  833.     fadd    st(1),st        ;ox tx=ox+oy2-ox2
  834.     fadd    st,st            ;2ox tx
  835.     fld1                ;1 2ox tx
  836.     fsubr                ;(1-2ox) tx
  837.     fmul    old+8            ;ty=oy(1-2ox) tx
  838.     fld    st(1)            ;tx ty tx -- duplicate these now
  839.     fld    st(1)            ;ty tx ty tx
  840.     mov    bx,floatparm
  841.     fld    qword ptr [bx+8]    ;py ty tx ty tx -- load y first
  842.     fld    qword ptr [bx]        ;px py ty tx ty tx
  843.     fmul    st(5),st        ;px py ty tx ty pxtx
  844.     fmulp    st(4),st        ;py ty tx pxty pxtx
  845.     fmul    st(2),st        ;py ty pytx pxty pxtx
  846.     fmul                ;pyty pytx pxty pxtx
  847.     fsubp    st(3),st        ;pytx pxty nx=pxtx-pyty
  848.     fadd                ;ny=pxty+pytx nx
  849.     fstp    qword ptr new+8    ; newx
  850.     fstp    qword ptr new    ; stack is empty
  851. ;    call    near ptr asmfloatbailout
  852.     call    word ptr [floatbailout]
  853.     ret
  854. FLambdaFPFractal endp
  855.  
  856. ; The following is no longer used.
  857. asmfloatbailout proc near
  858.     ; called with new.y and new.x on stack and clears the stack
  859.     ; destroys SI and DI: caller must save them
  860.     fst    qword ptr new+8
  861.     fmul    st,st            ;/* ny2 nx */
  862.     fst    tempsqry
  863.     fxch                ;/* nx ny2 */
  864.     fst    qword ptr new
  865.     fmul    st,st            ;/* nx2 ny2 */
  866.     fst    tempsqrx
  867.     fadd
  868.     fst    magnitude
  869.     fcomp    rqlim            ;/*** stack is empty */
  870.     fstsw    ax            ;/*** 287 and up only */
  871.     sahf
  872.     jae    bailout
  873.     mov    si,offset new
  874.     mov    di,offset old
  875.     mov    ax,ds
  876.     mov    es,ax
  877.     mov    cx,8
  878.     rep    movsw
  879.     xor    ax,ax
  880.     ret
  881. bailout:
  882.     mov    ax,1
  883.     ret
  884. asmfloatbailout endp
  885. ; The preceeding is no longer used.
  886.  
  887. asmfpMODbailout proc near uses si di
  888.     fld    qword ptr new+8
  889.     fmul    st,st            ;/* ny2 */
  890.     fst    tempsqry
  891.     fld    qword ptr new    ;/* nx ny2 */
  892.     fmul    st,st            ;/* nx2 ny2 */
  893.     fst    tempsqrx
  894.     fadd
  895.     fst    magnitude
  896.     fcomp    rqlim            ;/*** stack is empty */
  897.     fstsw    ax            ;/*** 287 and up only */
  898.     sahf
  899.     jae    bailout
  900.     mov    si,offset new
  901.     mov    di,offset old
  902.     mov    ax,ds
  903.     mov    es,ax
  904.     mov    cx,8
  905.     rep    movsw
  906.     xor    ax,ax
  907.     ret
  908. bailout:
  909.     mov    ax,1
  910.     ret
  911. asmfpMODbailout endp
  912.  
  913. asmfpREALbailout proc near uses si di
  914.     fld    qword ptr new
  915.     fmul    st,st            ;/* nx2 */
  916.     fst    tempsqrx
  917.     fld    qword ptr new+8    ;/* ny nx2 */
  918.     fmul    st,st            ;/* ny2 nx2 */
  919.     fst    tempsqry        ;/* ny2 nx2 */
  920.     fadd    st,st(1)        ;/* ny2+nx2 nx2 */
  921.     fstp    magnitude        ;/* nx2 */
  922.     fcomp    rqlim            ;/*** stack is empty */
  923.     fstsw    ax            ;/*** 287 and up only */
  924.     sahf
  925.     jae    bailout
  926.     mov    si,offset new
  927.     mov    di,offset old
  928.     mov    ax,ds
  929.     mov    es,ax
  930.     mov    cx,8
  931.     rep    movsw
  932.     xor    ax,ax
  933.     ret
  934. bailout:
  935.     mov    ax,1
  936.     ret
  937. asmfpREALbailout endp
  938.  
  939. asmfpIMAGbailout proc near uses si di
  940.     fld    qword ptr new+8
  941.     fmul    st,st            ;/* ny2 */
  942.     fst    tempsqry
  943.     fld    qword ptr new    ;/* nx ny2 */
  944.     fmul    st,st            ;/* nx2 ny2 */
  945.     fst    tempsqrx        ;/* nx2 ny2 */
  946.     fadd    st,st(1)        ;/* nx2+ny2 ny2 */
  947.     fstp    magnitude        ;/* ny2 */
  948.     fcomp    rqlim            ;/*** stack is empty */
  949.     fstsw    ax            ;/*** 287 and up only */
  950.     sahf
  951.     jae    bailout
  952.     mov    si,offset new
  953.     mov    di,offset old
  954.     mov    ax,ds
  955.     mov    es,ax
  956.     mov    cx,8
  957.     rep    movsw
  958.     xor    ax,ax
  959.     ret
  960. bailout:
  961.     mov    ax,1
  962.     ret
  963. asmfpIMAGbailout endp
  964.  
  965. asmfpORbailout proc near uses si di
  966.     fld    qword ptr new+8
  967.     fmul    st,st            ;/* ny2 */
  968.     fst    tempsqry
  969.     fld    qword ptr new    ;/* nx ny2 */
  970.     fmul    st,st            ;/* nx2 ny2 */
  971.     fst    tempsqrx
  972.     fld    st(1)            ;/* ny2 nx2 ny2 */
  973.     fadd    st,st(1)        ;/* ny2+nx2 nx2 ny2 */
  974.     fstp    magnitude        ;/* nx2 ny2 */
  975.     fcomp    rqlim            ;/* ny2 */
  976.     fstsw    ax            ;/*** 287 and up only */
  977.     sahf
  978.     jae    bailoutp
  979.     fcomp    rqlim            ;/*** stack is empty */
  980.     fstsw    ax            ;/*** 287 and up only */
  981.     sahf
  982.     jae    bailout
  983.     mov    si,offset new
  984.     mov    di,offset old
  985.     mov    ax,ds
  986.     mov    es,ax
  987.     mov    cx,8
  988.     rep    movsw
  989.     xor    ax,ax
  990.     ret
  991. bailoutp:
  992.     finit        ;/* cleans up stack */
  993. bailout:
  994.     mov    ax,1
  995.     ret
  996. asmfpORbailout endp
  997.  
  998. asmfpANDbailout proc near uses si di
  999.     fld    qword ptr new+8
  1000.     fmul    st,st            ;/* ny2 */
  1001.     fst    tempsqry
  1002.     fld    qword ptr new    ;/* nx ny2 */
  1003.     fmul    st,st            ;/* nx2 ny2 */
  1004.     fst    tempsqrx
  1005.     fld    st(1)            ;/* ny2 nx2 ny2 */
  1006.     fadd    st,st(1)        ;/* ny2+nx2 nx2 ny2 */
  1007.     fstp    magnitude        ;/* nx2 ny2 */
  1008.     fcomp    rqlim            ;/* ny2 */
  1009.     fstsw    ax            ;/*** 287 and up only */
  1010.     sahf
  1011.     jb    nobailoutp
  1012.     fcomp    rqlim            ;/*** stack is empty */
  1013.     fstsw    ax            ;/*** 287 and up only */
  1014.     sahf
  1015.     jae    bailout
  1016.     jmp    short nobailout
  1017. nobailoutp:
  1018.     finit        ;/* cleans up stack */
  1019. nobailout:
  1020.     mov    si,offset new
  1021.     mov    di,offset old
  1022.     mov    ax,ds
  1023.     mov    es,ax
  1024.     mov    cx,8
  1025.     rep    movsw
  1026.     xor    ax,ax
  1027.     ret
  1028. bailout:
  1029.     mov    ax,1
  1030.     ret
  1031. asmfpANDbailout endp
  1032.  
  1033. .8086
  1034. .8087
  1035.  
  1036.     end
  1037.  
  1038.